﻿using System;
using System.Collections.Generic;
using System.Text;
using Vortex.Wrapper.Direct3D;

namespace Vortex.Drawing {

	/// <summary>
	/// 2D vertex used by Vortex2D.NET as primary vertex format
	/// </summary>
	public struct Vertex2D {
		/// <summary>Position of vertex in 2D space</summary>
		public Vector2 XY;
		///<summary>Z-value of vertex</summary>
		public float Z;
		///<summary>Vertex color</summary>
		public ColorU Color;
		///<summary>Primary texture coordinates for vertex</summary>
		public Vector2 UV1;
		///<summary>Secondary texture coordinates for vertex</summary>
		public Vector2 UV2;

		#region Properties
		/// <summary>
		/// Gets or sets the XYZ position of vertex in 3D space.
		/// </summary>
		/// <value>The <see cref="Vector3"/> value.</value>
		public Vector3 XYZ {
			get { return XY.ToVector3(Z); }
			set { XY.X = value.X; XY.Y = value.Y; Z = value.Z; }
		}

		#endregion

		public Vertex2D(Vector2 XY)
			: this(XY, 0.0f, ColorU.Blank, Vector2.Zero, Vector2.Zero) {
		}

        public Vertex2D(float X, float Y)
            : this(new Vector2(X, Y)) {
        }

		public Vertex2D(Vector2 XY, float Z)
			: this(XY, Z, ColorU.Blank, Vector2.Zero, Vector2.Zero) {
		}

		public Vertex2D(Vector2 XY, ColorU color)
			: this(XY, 0.0f, color, Vector2.Zero, Vector2.Zero) {
		}

		public Vertex2D(Vector2 XY, float Z, ColorU color)
			: this(XY, Z, color, Vector2.Zero, Vector2.Zero) {
		}


		public Vertex2D(Vector2 XY, float Z, ColorU color, Vector2 uv1)
			: this(XY, Z, color, uv1, Vector2.Zero) {
		}

		public Vertex2D(Vector2 XY, float Z, ColorU color, Vector2 uv1, Vector2 uv2) {
			this.XY = XY;
			this.Z = Z;
			this.Color = color;
			this.UV1 = uv1;
			this.UV2 = uv2;
		}

		private static D3DVertexElement[] _declarationElements = new D3DVertexElement[] {
			new D3DVertexElement(0, D3DDeclType.Float3, D3DDeclUsage.Position),
			new D3DVertexElement(12, D3DDeclType.Color, D3DDeclUsage.Color),
			new D3DVertexElement(16, D3DDeclType.Float2, D3DDeclUsage.TextCoord, 0),
			new D3DVertexElement(24, D3DDeclType.Float2, D3DDeclUsage.TextCoord, 1),
			D3DVertexElement.End
		};

		/// <summary>
		/// Gets the vertex declaration elements.
		/// </summary>
		/// <value>The declaration elements.</value>
		internal static D3DVertexElement[] DeclarationElements {
			get { return _declarationElements; }
		}
	}
}
